package com.wenyu.wenyuyuedu.mytestdemo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.wenyu.wenyuyuedu.R;

import java.util.List;


/**
 * Created by lenovo on 2017/3/12.
 */

public class MyHorizontalAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<Integer> mlist;
    private LayoutInflater mInflater;

    public MyHorizontalAdapter(Context context, List<Integer> mlist) {
        mInflater = LayoutInflater.from(context);
        this.context = context;
        this.mlist = mlist;

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.activity_index_gallery_item,
                parent, false);

        return new MyViewHold(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((MyViewHold) holder).imageView.setImageResource(mlist.get(position));
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    class MyViewHold extends RecyclerView.ViewHolder {

        private ImageView imageView;

        public MyViewHold(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.id_index_gallery_item_image);
        }
    }
}
